home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / 8bit / cislib_a / catch.act < prev    next >
Text File  |  1995-04-22  |  2KB  |  109 lines

  1.  
  2. MODULE ; CATCH.ACT 
  3.  
  4. ; copyright (c) 1984 
  5. ; by Action Computer Services 
  6. ; All Rights Reserved 
  7.  
  8. ; This module provides two PROCs 
  9. ; (Catch and Throw) which can be used 
  10. ; for error trapping (and flow 
  11. ; control, yeck!) in ACTION!.  To 
  12. ; use them, you must call the Catch 
  13. ; PROC to indicate where you want 
  14. ; the program to continue when you 
  15. ; call Throw.  When throw is called, 
  16. ; execution will continue following 
  17. ; the last call to Catch with the 
  18. ; same index as the call to Throw. 
  19. ; Calling Catch is similar (but not 
  20. ; identical) to TRAP in BASIC.  It 
  21. ; differs in that the actual trapping 
  22. ; is generated by the user (by 
  23. ; calling Throw) and that you can 
  24. ; have multiple Catch'ers active at 
  25. ; one time.  Also, you cannot Throw 
  26. ; to a Catcher that is no longer  
  27. ; active (the PROC/FUNC containing 
  28. ; it has RETURN to it's caller).  The 
  29. ; Throw procedure tries to check for 
  30. ; this error, but it is possible to 
  31. ; fool it into thinking it's OK.  If 
  32. ; you want to solve this problem, you 
  33. ; can set 'c_t_sp(index)' to zero 
  34. ; before you return from the PROC 
  35. ; that contained the Catch(index). 
  36. ; If index is greater than 24 or 
  37. ; if there is no matching Catch index 
  38. ; for the Throw, then Error will be 
  39. ; called with a value of CTERR 
  40. ; (defined below to be 71).  If you 
  41. ; setup your own Error procedure and 
  42. ; use Catch and Throw, your error 
  43. ; procedure should handle this error 
  44. ; as well or your program will most 
  45. ; likely "go off the deep end". 
  46.  
  47.  
  48. DEFINE CTERR = "71"  
  49.  
  50. BYTE ARRAY c_t_sp(25)=[0 0 0 0 0 0 0 
  51.  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 
  52. BYTE ARRAY c_t_hi(25), c_t_lo(25) 
  53.  
  54.  
  55. PROC Catch(BYTE index) 
  56.   DEFINE TSX="$BA", TXA="$8A", 
  57.          LDYA="$AC", STAY="$99", 
  58.          PLA="$68", LDAY="$B9", 
  59.          PHA="$48" 
  60.  
  61.   IF index>=25 THEN 
  62.     Error(CTERR,0,CTERR) FI  
  63.  
  64.   [ 
  65.     LDYA index   
  66.     PLA 
  67.     STAY c_t_hi 
  68.     PLA 
  69.     STAY c_t_lo 
  70.     TSX 
  71.     TXA 
  72.     STAY c_t_sp 
  73.     LDAY c_t_lo 
  74.     PHA 
  75.     LDAY c_t_hi 
  76.     PHA 
  77.   ] 
  78. RETURN 
  79.  
  80.  
  81. PROC Throw(BYTE index) 
  82.   DEFINE TXS="$9A", PHA="$48", 
  83.          LDYA="$AC", STX="$86", 
  84.          TSX="$BA", TAX="$AA", 
  85.          LDAY="$B9" 
  86.  
  87.   BYTE sp=$A2 
  88.  
  89. ; get current stack pointer 
  90.   [ TSX : STX sp ] 
  91.  
  92.   IF index>=25 OR sp+2>c_t_sp(index) 
  93.     THEN Error(CTERR,0,CTERR) FI  
  94.  
  95.   [ 
  96.     LDYA index   
  97.     LDAY c_t_sp 
  98.     TAX 
  99.     TXS 
  100.     LDAY c_t_lo 
  101.     PHA 
  102.     LDAY c_t_hi 
  103.     PHA 
  104.   ] 
  105. RETURN 
  106.  
  107. MODULE ; just in case 
  108.  
  109.